package org.point.service.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.point.common.service.impl.BaseServiceImpl;
import org.point.common.util.DoPage;
import org.point.dao.impl.CreditsBehaviorDaoImpl;
import org.point.domain.CreditsBehavior;
import org.point.service.CreditsBehaviorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @ClassName: CreditsBehaviorServiceImpl  
 * @Description: TODO(积分行为对象业务接口类)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午4:02:01  
 *
 */
@Service("creditsBehaviorService")
public class CreditsBehaviorServiceImpl extends BaseServiceImpl<CreditsBehavior, Serializable> implements CreditsBehaviorService {
	
	@Autowired
	private CreditsBehaviorDaoImpl dao;

	public List<CreditsBehavior> searchCreditsBehavior(DoPage<CreditsBehavior> page) {
		List<CreditsBehavior> records = dao.findCBForMem(page);
		
		return null;
	}

	public DoPage<CreditsBehavior> searchCBForPage(DoPage<CreditsBehavior> page) {
		List<CreditsBehavior> records = dao.findCBForMem(page);
		Integer totalRecords = dao.countCBForMem(page);
		
		System.out.println(totalRecords);
		for (CreditsBehavior record : records) {
			System.out.println(record.getBehaviorName());
		}
		
		page.setTotalRecords(totalRecords);
		page.setList(records);
		return page;
	}
	
	public Integer countCreditsBehavior(DoPage<CreditsBehavior> page) {
		// TODO Auto-generated method stub
		return null;
	}

	public Integer insertCreditsBehavior(CreditsBehavior record,String cbCode) {
		Integer result = 0;
		if(record.getId()!=null){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", record.getId());
			Integer isdel = dao.delCBbyId(map);
			record.setDelFlag(new Byte("0"));
			Integer newResult = dao.insertCB(record);
			if(isdel+newResult>0){
				result = 1;
			}
		}else{
			record.setDelFlag(new Byte("0"));
			record.setBehaviorId(cbCode);;
		    result = dao.insertCB(record);
		}
		return result;
	}

	public Integer editCreditsBehavior(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return null;
	}

	public CreditsBehavior getCBByCBID(Map<String, Object> map) {
		CreditsBehavior record = dao.searchCBid(map);
		return record;
	}

	public Integer deleteCBids(Map<String, Object> map) {
		Integer result = dao.delCBids(map);
		return result;
	}
	
}
